﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;

public partial class learning_in : System.Web.UI.Page
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;
    private SessionHelper m_SessionHelper;
    private int m_PostId = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();
        m_SessionHelper = new SessionHelper();
        m_PostId = QueryStringHelper.GetInteger("post", 0);

        if (m_SessionHelper.Member == null)
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJSAndRedirect("請先登入會員。", "login.aspx"), false);
            return;
        }

        if (!IsPostBack)
        {
            PostVO postVO = m_PostService.GetPostByIdNoLazy(m_PostId);
            if (postVO != null)
            {
                ltlTitle.Text = postVO.Title;
                hdnId.Value = postVO.PostId.ToString();
                if (!string.IsNullOrEmpty(postVO.DocFileName))
                {
                    linkDownFile.Enabled = true;
                    //linkDownFile.NavigateUrl = string.Format("upload/{0}", postVO.DocFileName);
                    linkDownFile.NavigateUrl = string.Format("learning2_in.aspx?post={0}", postVO.PostId);
                }
                else
                {
                    linkDownFile.Enabled = false;
                }

                if (!string.IsNullOrEmpty(postVO.PicFileName))
                {
                    ltlVideo.Text = string.Format("<embed src='upload/{0}' width='581' height='353' type='application/x-mplayer2' wmode='transparent' showstatusbar='1' autostart='true'></embed>", postVO.PicFileName);
                }
                else
                {
                    ltlVideo.Text = "尚未提供影片課程";
                }
            }
            else
            {
                Response.Redirect("learning.aspx");
            }
        }
    }

    protected void btnTest_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("learning_test.aspx?post={0}", hdnId.Value));
    }
}